﻿@model Model.CodeMapping
@{
    ViewBag.Title = "UserEdit";
    Layout = "~/Views/Shared/_Main.cshtml";
}
<style type="text/css">
    textarea
    {
        width: 400px;
        border: 1px solid #ccc;
        padding: 2px;
    }
    .pwdw
    {
        width: 148px;
    }
    .hide
    {
        display: none;
    }
</style>
<script type="text/javascript">
    $(function () {
        $.ajax({
            type: "POST",
            async: false,  // 设置同步方式 
            url: "/PEPara/DropDownList/?keyName=DotNetCode",
            success: function (result) {
                var arr_sel = new Array();
                if (result != "") {
                    for (var i = 0; i < result.length; i++) {
                        arr_sel.push("<option value='");
                        arr_sel.push(result[i].Value);
                        arr_sel.push("'>");
                        arr_sel.push(result[i].Name);
                        arr_sel.push("</option>");
                    }
                    $("#ddlDotNetCode").append(arr_sel.join(""));
                    $("#ddlDotNetCode").val("@Model.DotNetCode");
                }
            }
        });

        $.ajax({
            type: "POST",
            async: false,  // 设置同步方式 
            url: "/PEPara/DropDownList/?keyName=TargetDBCode",
            success: function (result) {
                var arr_sel = new Array();
                if (result != "") {
                    for (var i = 0; i < result.length; i++) {
                        arr_sel.push("<option value='");
                        arr_sel.push(result[i].Value);
                        arr_sel.push("'>");
                        arr_sel.push(result[i].Name);
                        arr_sel.push("</option>");
                    }
                    $("#ddlDBCode").append(arr_sel.join(""));
                    $("#ddlDBCode").val("@Model.DBCode");
                }
            }
        });
    })
    function SubmitForm() {
        if ($('#ff').form("validate")) {
            if (IsNullOrEmpty($("#txtName").val())) {
                alert("名称不能为空！");
                return false;
            }
            $.post("/CodeMapping/SaveItem", { query: jv.GetDivJson($("#formArea"), 3), dbName: encodeURI($.getUrlParam("dbName")) }, function (res) {
                if (res == 1) {
                    alert("操作成功！");
                    BackToList();
                } else if (res == -1) {
                    alert("操作失败。");
                } else
                    alert(res);
            });
        }
    }
    function BackToList() {
        window.location.href = "/CodeMapping/List?dbName=" + encodeURI($.getUrlParam("dbName"));
    }
  
</script>
<div style="margin: 5px;">
    <div id="p" class="easyui-panel" style="width: 800px; padding: 10px 5px 10px 5px;"
        data-options="title:'映射编辑',iconCls:'icon-edit'">
        <form id="ff" method="post">
        <table id="formArea" class="table_bg" style="background: #ffffff; width: 780px">
            <tr>
                <td style="width: 100px; text-align: right; height: 30px;">
                    名称：
                </td>
                <td>
                    <input type="hidden" id="hidGUID" value="@Model.Guid" />
                    <input type="text" id="txtName" value="@Model.Name" style="width: 220px" class="easyui-validatebox"
                        data-options="required:true" />
                </td>
            </tr>
            <tr>
                <td style="width: 50px; text-align: right; height: 30px;">
                    DotNet编码：
                </td>
                <td>
                    <select id="ddlDotNetCode">
                    </select>
                </td>
            </tr>
            <tr>
                <td style="width: 50px; text-align: right; height: 30px;">
                    数据库编码：
                </td>
                <td>
                    <select id="ddlDBCode">
                    </select>
                </td>
            </tr>
            <tr>
                <td style="width: 50px; text-align: right; height: 30px;">
                    描述：
                </td>
                <td>
                    <textarea id="txtDescription" style="width: 420px; height: 100px">@Model.Description</textarea>
                </td>
            </tr>
            <tr>
                <td style="width: 50px; text-align: right; height: 30px;">
                    排序号：
                </td>
                <td>
                    <input type="text" id="txtOrderNo" value="@(Model.OrderNo == null ? "1" : Model.OrderNo)" class="easyui-numberspinner" data-options="required:true" />
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td>
                    <input type="button" value=" 保存 " onclick="return SubmitForm()" />
                    <input type="button" value=" 返回 " onclick="BackToList();" />
                </td>
            </tr>
        </table>
        </form>
    </div>
</div>
